////////////////////////////////////////////////////////////////////////////////
/// @file     KEY.C
/// @author   AE TEAM
/// @brief    THIS FILE PROVIDES ALL THE SYSTEM FUNCTIONS.
////////////////////////////////////////////////////////////////////////////////
/// @attention
///
/// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
/// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
/// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
/// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
/// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
/// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
///
/// <H2><CENTER>&COPY; COPYRIGHT MINDMOTION </CENTER></H2>
////////////////////////////////////////////////////////////////////////////////

// Define to prevent recursive inclusion
#define _KEY_C_

// Files includes
#include "key.h"
#include "delay.h"

////////////////////////////////////////////////////////////////////////////////
/// @addtogroup MM32_Example_Layer
/// @{

////////////////////////////////////////////////////////////////////////////////
/// @addtogroup KEY
/// @{

////////////////////////////////////////////////////////////////////////////////
/// @addtogroup KEY_Exported_Constants
/// @{

////////////////////////////////////////////////////////////////////////////////
/// @brief     key initial
/// @param     None
/// @retval    None
////////////////////////////////////////////////////////////////////////////////
void KEY_Init(void)
{
    //RCC->AHBENR |= 0x1 << 17; //RCC->APB1ENR|=1<<2;  //enable GPIOA clock
    GPIOA->CRL &= ~(GPIO_CNF_MODE_MASK << GPIO_CRL_CNF_MODE_4_Pos ); //IO status set
    GPIOA->CRL |= GPIO_CNF_MODE_INPUPD << GPIO_CRL_CNF_MODE_4_Pos; //IO status set    PA0
    GPIOA->ODR |= GPIO_ODR_ODR4;
}
////////////////////////////////////////////////////////////////////////////////
/// @brief  Keyboard Scanning
/// @note   None.
/// @param  None.
/// @retval Keyboard value.
////////////////////////////////////////////////////////////////////////////////
u8 KEY_Scan(u8 mode)
{
    static u8 key_up = 1;
    if(mode)key_up = 1;

    if(key_up && (KEY2 == 0)) {
        DELAY_Ms(10);
        key_up = 0;
        if(KEY2 == 0)
            return SW2_PRES;
    }
    else if(KEY2 == 1)
        key_up = 1;
    return 0;
}


/// @}


/// @}

/// @}

